//
//  DAPersonalBorrowBookTableViewCell.m
//  DAKnowledge
//
//  Created by DreamArts on 16/5/3.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DAPersonalBorrowBookTableViewCell.h"
#import "Utility.h"
#import "DAPersonalShowBookStatusModel.h"
#import "DAHeader.h"
#import "DAImageView.h"
#import "UIImageView+WebCache.h"
#import "DALabel.h"

@interface DAPersonalBorrowBookTableViewCell ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ViewHeight;

@property (nonatomic, copy) NSString *buttonStr;
@property (weak, nonatomic) IBOutlet UIView *midBookImageBackView;
@property (weak, nonatomic) IBOutlet UIView *rightBookImageBackVIew;
@property (weak, nonatomic) IBOutlet UIView *leftBookImageBackView;
@property (nonatomic, assign) BOOL isLeft;
@property (nonatomic, assign) BOOL isMiddle;
@property (nonatomic, assign) BOOL isRight;
@end

@implementation DAPersonalBorrowBookTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setModelArray:(NSMutableArray *)modelArray{
    if (_modelArray != modelArray) {
        _modelArray = modelArray;
    }

    if (modelArray.count == 1) {
        self.isLeft = YES;
        self.isMiddle = NO;
        self.isRight = NO;
        self.leftPersonalBookManageModel = modelArray[0];
        [self setLeftModel:modelArray[0]];
        [self setMiddleModel:nil];
        [self setRightModel:nil];
        self.midPersonalBookManageModel = nil;
        self.rightPersonalBookManageModel = nil;
        self.leftBookImageBackView.backgroundColor = [UIColor whiteColor];
        self.midBookImageBackView.backgroundColor = [UIColor colorWithHexString:backGroundColor];
        self.rightBookImageBackVIew.backgroundColor = [UIColor colorWithHexString:backGroundColor];
        self.bottomLineLabel.backgroundColor = [UIColor colorWithHexString:cellBottomLineColor];
    }else if (modelArray.count == 2){
        self.isLeft = YES;
        self.isMiddle = YES;
        self.isRight = NO;
        self.leftPersonalBookManageModel = modelArray[0];
        self.midPersonalBookManageModel = modelArray[1];
        [self setLeftModel:modelArray[0]];
        [self setMiddleModel:modelArray[1]];
        [self setRightModel:nil];
        self.rightPersonalBookManageModel = nil;
        self.leftBookImageBackView.backgroundColor = [UIColor whiteColor];
        self.midBookImageBackView.backgroundColor = [UIColor whiteColor];
        self.rightBookImageBackVIew.backgroundColor = [UIColor colorWithHexString:backGroundColor];
        self.bottomLineLabel.backgroundColor = [UIColor colorWithHexString:cellBottomLineColor];
    }else if(modelArray.count == 3){
        self.isLeft = YES;
        self.isMiddle = YES;
        self.isRight = YES;
        self.leftPersonalBookManageModel = modelArray[0];
        self.midPersonalBookManageModel = modelArray[1];
        self.rightPersonalBookManageModel = modelArray[2];
        [self setLeftModel:modelArray[0]];
        [self setMiddleModel:modelArray[1]];
        [self setRightModel:modelArray[2]];
        self.leftBookImageBackView.backgroundColor = [UIColor whiteColor];
        self.midBookImageBackView.backgroundColor = [UIColor whiteColor];
        self.rightBookImageBackVIew.backgroundColor = [UIColor whiteColor];
        self.bottomLineLabel.backgroundColor = [UIColor colorWithHexString:cellBottomLineColor];
    }else{
        self.isLeft = NO;
        self.isMiddle = NO;
        self.isRight = NO;
        [self setLeftModel:nil];
        [self setMiddleModel:nil];
        [self setRightModel:nil];
        self.leftBookImageBackView.backgroundColor = [UIColor colorWithHexString:backGroundColor];
        self.midBookImageBackView.backgroundColor = [UIColor colorWithHexString:backGroundColor];
        self.rightBookImageBackVIew.backgroundColor = [UIColor colorWithHexString:backGroundColor];
        self.bottomLineLabel.backgroundColor = [UIColor colorWithHexString:backGroundColor];
    }
    
}
- (void)layoutSubviews{
    [super layoutSubviews];
    if (self.bounds.size.width > 375) {
        self.ViewHeight.constant = 150;
    }else if(self.bounds.size.width == 375) {
        self.ViewHeight.constant = 135;
    } else{
        self.ViewHeight.constant = 110;
    }
    self.leftBook.contentMode = UIViewContentModeScaleAspectFill;
    self.leftBook.clipsToBounds = YES;
    [self.middleBook setContentMode:UIViewContentModeScaleAspectFill];
    self.middleBook.clipsToBounds = YES;
    [self.rightBook setContentMode:UIViewContentModeScaleAspectFill];
    self.rightBook.clipsToBounds = YES;
    self.leftBook.userInteractionEnabled = YES;
    self.middleBook.userInteractionEnabled = YES;
    self.rightBook.userInteractionEnabled = YES;
    self.leftButton.userInteractionEnabled = NO;
    self.middleButton.userInteractionEnabled = NO;
    self.rightButton.userInteractionEnabled = NO;
    UITapGestureRecognizer *leftTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickLeftBook:)];
    [self.leftBook addGestureRecognizer:leftTap];
    
    UITapGestureRecognizer *middleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickMiddleBook:)];
    [self.middleBook addGestureRecognizer:middleTap];
    
    UITapGestureRecognizer *rightTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickRightBook:)];
    [self.rightBook addGestureRecognizer:rightTap];
    
//    if (self.number == 0) {
//        self.leftBookImageBackView.backgroundColor = [UIColor colorWithHexString:backGroundColor];
//        self.midBookImageBackView.backgroundColor = [UIColor colorWithHexString:backGroundColor];
//        self.rightBookImageBackVIew.backgroundColor = [UIColor colorWithHexString:backGroundColor];
//    }else if(self.number == 1){
//       self.leftBookImageBackView.backgroundColor = [UIColor whiteColor];
//       self.midBookImageBackView.backgroundColor = [UIColor colorWithHexString:backGroundColor];
//       self.rightBookImageBackVIew.backgroundColor = [UIColor colorWithHexString:backGroundColor];
//    }else if(self.number == 2) {
//        self.leftBookImageBackView.backgroundColor = [UIColor whiteColor];
//        self.midBookImageBackView.backgroundColor = [UIColor whiteColor];
//        self.rightBookImageBackVIew.backgroundColor = [UIColor colorWithHexString:backGroundColor];
//    }else if(self.number == 3){
//        self.leftBookImageBackView.backgroundColor = [UIColor whiteColor];
//        self.midBookImageBackView.backgroundColor = [UIColor whiteColor];
//        self.rightBookImageBackVIew.backgroundColor = [UIColor whiteColor];
//    }
    
}
#pragma mark - 点击了左边图片
- (void)clickLeftBook:(UITapGestureRecognizer *)tap{
    NSLog(@"点击了左边图片");
    [self.delegate showBookStatus:self.leftPersonalBookManageModel
                       bookStatus:self.leftButton.titleLabel.text
                        withColor:self.leftButton.backgroundColor];
}
#pragma mark - 点击了中间图片
- (void)clickMiddleBook:(UITapGestureRecognizer *)tap{
     NSLog(@"点击了中间图片");
    //[self.delegate showBookStatus:@"middle"];
    
    [self.delegate showBookStatus:self.midPersonalBookManageModel bookStatus:self.middleButton.titleLabel.text withColor:self.middleButton.backgroundColor];
}
#pragma mark - 点击了右边图片
- (void)clickRightBook:(UITapGestureRecognizer *)tap{
     NSLog(@"点击了右边图片");
  //  [self.delegate showBookStatus:@"right"];
    
    [self.delegate showBookStatus:self.rightPersonalBookManageModel bookStatus:self.rightButton.titleLabel.text withColor:self.rightButton.backgroundColor];
    
}


- (void)setLeftModel:(DAPersonalBookManageModel *)leftPersonalBookManageModel{
    if (leftPersonalBookManageModel == nil) {
        self.leftBook.hidden = YES;
        self.leftBorrowTimeLabel.hidden = YES;
        self.leftButton.hidden = YES;
        
    }else{
        
        self.leftBook.hidden = NO;
        self.leftBorrowTimeLabel.hidden = NO;
        self.leftButton.hidden = NO;
        
        UIView *bookCover = [[UIView alloc]initWithFrame:CGRectMake(0 , 0, (SCREENWIDTH - 40) / 3 - 10, self.leftBook.frame.size.height)];
        bookCover.backgroundColor = [UIColor supportGreenColor];
        DALabel *bookCoverName = [[DALabel alloc]initWithFrame:CGRectMake(5, 5, bookCover.frame.size.width -10, bookCover.frame.size.height - 10)];
        [bookCoverName setText:leftPersonalBookManageModel.bookName fitToContent:YES];
        [bookCoverName setTextColor:[UIColor whiteColor]];
        bookCoverName.font = [UIFont systemFontOfSize:12];
        bookCoverName.verticalAlignment = VerticalAlignmentMiddle;
        bookCoverName.textAlignment = NSTextAlignmentCenter;
        [bookCover addSubview:bookCoverName];
        
        UIImage *image = [self makeImageWithView:bookCover];
        [self.leftBook sd_setImageWithURL:[NSURL URLWithString:leftPersonalBookManageModel.bookImage] placeholderImage:image];
        
        // [self.leftBook sd_setImageWithURL:[NSURL URLWithString:leftPersonalBookManageModel.bookImage]];
        NSString *str = leftPersonalBookManageModel.borrowDate;
        self.leftBorrowTimeLabel.text = [NSString stringWithFormat:@"%@",[str substringToIndex:11]];
        self.leftBorrowTimeLabel.textColor = [UIColor colorWithHexString:borrowTimeColor];
        [self intervalSinceNow:leftPersonalBookManageModel.borrowEnd borrowStatus:leftPersonalBookManageModel.borrowStatus button:self.leftButton];
        [self.leftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.bottomLineLabel.backgroundColor = [UIColor colorWithHexString:cellBottomLineColor];
    }
    
    
}




//
//- (void)setLeftPersonalBookManageModel:(DAPersonalBookManageModel *)leftPersonalBookManageModel{
//    if (_leftPersonalBookManageModel != leftPersonalBookManageModel) {
//        _leftPersonalBookManageModel = leftPersonalBookManageModel;
//    }
//    if (self.isLeft) {
//        
//        UIView *bookCover = [[UIView alloc]initWithFrame:CGRectMake(0 , 0, (SCREENWIDTH - 40) / 3 - 10, self.leftBook.frame.size.height)];
//        bookCover.backgroundColor = [UIColor supportGreenColor];
//        DALabel *bookCoverName = [[DALabel alloc]initWithFrame:CGRectMake(5, 5, bookCover.frame.size.width -10, bookCover.frame.size.height - 10)];
//        [bookCoverName setText:leftPersonalBookManageModel.bookName fitToContent:YES];
//        [bookCoverName setTextColor:[UIColor whiteColor]];
//        bookCoverName.font = [UIFont systemFontOfSize:12];
//        bookCoverName.verticalAlignment = VerticalAlignmentMiddle;
//        bookCoverName.textAlignment = NSTextAlignmentCenter;
//        [bookCover addSubview:bookCoverName];
//        
//        UIImage *image = [self makeImageWithView:bookCover];
//        [self.leftBook sd_setImageWithURL:[NSURL URLWithString:leftPersonalBookManageModel.bookImage] placeholderImage:image];
//        
//        // [self.leftBook sd_setImageWithURL:[NSURL URLWithString:leftPersonalBookManageModel.bookImage]];
//        NSString *str = leftPersonalBookManageModel.borrowDate;
//        self.leftBorrowTimeLabel.text = [NSString stringWithFormat:@"%@",[str substringToIndex:11]];
//        self.leftBorrowTimeLabel.textColor = [UIColor colorWithHexString:borrowTimeColor];
//        [self intervalSinceNow:leftPersonalBookManageModel.borrowEnd borrowStatus:leftPersonalBookManageModel.borrowStatus button:self.leftButton];
//        [self.leftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        self.bottomLineLabel.backgroundColor = [UIColor colorWithHexString:cellBottomLineColor];
//        
//    }else{
////        [self.leftBook removeFromSuperview];
////        [self.leftBorrowTimeLabel removeFromSuperview];
////        [self.leftButton removeFromSuperview];
//        
//        
//    }
//
//    
// 
//}


- (void)setMiddleModel:(DAPersonalBookManageModel *)midPersonalBookManageModel{
    
    if (midPersonalBookManageModel == nil) {
        self.middleBook.hidden = YES;
        self.middleBorrowTimeLabel.hidden = YES;
        self.middleButton.hidden = YES;
    }else{
        self.middleBook.hidden = NO;
        self.middleBorrowTimeLabel.hidden = NO;
        self.middleButton.hidden = NO;
        
        UIView *bookCover = [[UIView alloc]initWithFrame:CGRectMake(0 , 0, self.middleBook.frame.size.width, self.middleBook.frame.size.height)];
        bookCover.backgroundColor = [UIColor supportGreenColor];
        DALabel *bookCoverName = [[DALabel alloc]initWithFrame:CGRectMake(5, 5, bookCover.frame.size.width -10, bookCover.frame.size.height - 10)];
        [bookCoverName setText:midPersonalBookManageModel.bookName fitToContent:YES];
        [bookCoverName setTextColor:[UIColor whiteColor]];
        bookCoverName.font = [UIFont systemFontOfSize:12];
        bookCoverName.verticalAlignment = VerticalAlignmentMiddle;
        bookCoverName.textAlignment = NSTextAlignmentCenter;
        [bookCover addSubview:bookCoverName];
        
        UIImage *image = [self makeImageWithView:bookCover];
        [self.middleBook sd_setImageWithURL:[NSURL URLWithString:midPersonalBookManageModel.bookImage] placeholderImage:image];
        
        // [self.middleBook sd_setImageWithURL:[NSURL URLWithString:midPersonalBookManageModel.bookImage]];
        NSString *str = midPersonalBookManageModel.borrowDate;
        // NSString *borrowAt = NSLocalizedString(@"borrowAt", nil);
        self.middleBorrowTimeLabel.text = [NSString stringWithFormat:@"%@",[str substringToIndex:11]];
        self.middleBorrowTimeLabel.textColor = [UIColor colorWithHexString:borrowTimeColor];
        [self intervalSinceNow:midPersonalBookManageModel.borrowEnd borrowStatus:midPersonalBookManageModel.borrowStatus button:self.middleButton];
        [self.middleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.bottomLineLabel.backgroundColor = [UIColor colorWithHexString:cellBottomLineColor];
    }
    
}

//- (void)setMidPersonalBookManageModel:(DAPersonalBookManageModel *)midPersonalBookManageModel{
//    if (_midPersonalBookManageModel != midPersonalBookManageModel) {
//        _midPersonalBookManageModel = midPersonalBookManageModel;
//    }
//    if (self.isMiddle) {
//        
//        UIView *bookCover = [[UIView alloc]initWithFrame:CGRectMake(0 , 0, self.middleBook.frame.size.width, self.middleBook.frame.size.height)];
//        bookCover.backgroundColor = [UIColor supportGreenColor];
//        DALabel *bookCoverName = [[DALabel alloc]initWithFrame:CGRectMake(5, 5, bookCover.frame.size.width -10, bookCover.frame.size.height - 10)];
//        [bookCoverName setText:midPersonalBookManageModel.bookName fitToContent:YES];
//        [bookCoverName setTextColor:[UIColor whiteColor]];
//        bookCoverName.font = [UIFont systemFontOfSize:12];
//        bookCoverName.verticalAlignment = VerticalAlignmentMiddle;
//        bookCoverName.textAlignment = NSTextAlignmentCenter;
//        [bookCover addSubview:bookCoverName];
//        
//        UIImage *image = [self makeImageWithView:bookCover];
//        [self.middleBook sd_setImageWithURL:[NSURL URLWithString:midPersonalBookManageModel.bookImage] placeholderImage:image];
//        
//        // [self.middleBook sd_setImageWithURL:[NSURL URLWithString:midPersonalBookManageModel.bookImage]];
//        NSString *str = midPersonalBookManageModel.borrowDate;
//        // NSString *borrowAt = NSLocalizedString(@"borrowAt", nil);
//        self.middleBorrowTimeLabel.text = [NSString stringWithFormat:@"%@",[str substringToIndex:11]];
//        self.middleBorrowTimeLabel.textColor = [UIColor colorWithHexString:borrowTimeColor];
//        [self intervalSinceNow:midPersonalBookManageModel.borrowEnd borrowStatus:midPersonalBookManageModel.borrowStatus button:self.middleButton];
//        [self.middleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        self.bottomLineLabel.backgroundColor = [UIColor colorWithHexString:cellBottomLineColor];
//        
//    }else{
//        [self.middleBook removeFromSuperview];
//        [self.middleBorrowTimeLabel removeFromSuperview];
//        [self.middleButton removeFromSuperview];
//    }
//}

- (void)setRightModel:(DAPersonalBookManageModel *)rightPersonalBookManageModel{
    if (rightPersonalBookManageModel == nil) {
        
        self.rightBook.hidden = YES;
        self.rightBorrowTimeLabel.hidden = YES;
        self.rightButton.hidden = YES;
        
    }else{
        
        self.rightBook.hidden = NO;
        self.rightBorrowTimeLabel.hidden = NO;
        self.rightButton.hidden = NO;
        
        UIView *bookCover = [[UIView alloc]initWithFrame:CGRectMake(0 , 0, self.rightBook.frame.size.width, self.rightBook.frame.size.height)];
        bookCover.backgroundColor = [UIColor supportGreenColor];
        DALabel *bookCoverName = [[DALabel alloc]initWithFrame:CGRectMake(5, 5, bookCover.frame.size.width -10, bookCover.frame.size.height - 10)];
        [bookCoverName setText:rightPersonalBookManageModel.bookName fitToContent:YES];
        [bookCoverName setTextColor:[UIColor whiteColor]];
        bookCoverName.font = [UIFont systemFontOfSize:12];
        bookCoverName.verticalAlignment = VerticalAlignmentMiddle;
        bookCoverName.textAlignment = NSTextAlignmentCenter;
        [bookCover addSubview:bookCoverName];
        
        UIImage *image = [self makeImageWithView:bookCover];
        [self.rightBook sd_setImageWithURL:[NSURL URLWithString:rightPersonalBookManageModel.bookImage] placeholderImage:image];
        
        // [self.rightBook sd_setImageWithURL:[NSURL URLWithString:rightPersonalBookManageModel.bookImage]];
        NSString *str = rightPersonalBookManageModel.borrowDate;
        // NSString *borrowAt = NSLocalizedString(@"borrowAt", nil);
        self.rightBorrowTimeLabel.text = [NSString stringWithFormat:@"%@",[str substringToIndex:11]];
        self.rightBorrowTimeLabel.textColor = [UIColor colorWithHexString:borrowTimeColor];
        [self intervalSinceNow:rightPersonalBookManageModel.borrowEnd borrowStatus:rightPersonalBookManageModel.borrowStatus button:self.rightButton];
        [self.rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.bottomLineLabel.backgroundColor = [UIColor colorWithHexString:cellBottomLineColor];
    }
}

//- (void)setRightPersonalBookManageModel:(DAPersonalBookManageModel *)rightPersonalBookManageModel{
//    if (_rightPersonalBookManageModel != rightPersonalBookManageModel) {
//        _rightPersonalBookManageModel = rightPersonalBookManageModel;
//    }
//    if (self.isRight) {
//        UIView *bookCover = [[UIView alloc]initWithFrame:CGRectMake(0 , 0, self.rightBook.frame.size.width, self.rightBook.frame.size.height)];
//        bookCover.backgroundColor = [UIColor supportGreenColor];
//        DALabel *bookCoverName = [[DALabel alloc]initWithFrame:CGRectMake(5, 5, bookCover.frame.size.width -10, bookCover.frame.size.height - 10)];
//        [bookCoverName setText:rightPersonalBookManageModel.bookName fitToContent:YES];
//        [bookCoverName setTextColor:[UIColor whiteColor]];
//        bookCoverName.font = [UIFont systemFontOfSize:12];
//        bookCoverName.verticalAlignment = VerticalAlignmentMiddle;
//        bookCoverName.textAlignment = NSTextAlignmentCenter;
//        [bookCover addSubview:bookCoverName];
//        
//        UIImage *image = [self makeImageWithView:bookCover];
//        [self.rightBook sd_setImageWithURL:[NSURL URLWithString:rightPersonalBookManageModel.bookImage] placeholderImage:image];
//        
//        // [self.rightBook sd_setImageWithURL:[NSURL URLWithString:rightPersonalBookManageModel.bookImage]];
//        NSString *str = rightPersonalBookManageModel.borrowDate;
//        // NSString *borrowAt = NSLocalizedString(@"borrowAt", nil);
//        self.rightBorrowTimeLabel.text = [NSString stringWithFormat:@"%@",[str substringToIndex:11]];
//        self.rightBorrowTimeLabel.textColor = [UIColor colorWithHexString:borrowTimeColor];
//        [self intervalSinceNow:rightPersonalBookManageModel.borrowEnd borrowStatus:rightPersonalBookManageModel.borrowStatus button:self.rightButton];
//        [self.rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        self.bottomLineLabel.backgroundColor = [UIColor colorWithHexString:cellBottomLineColor];
//    }else{
//        [self.rightBook removeFromSuperview];
//        [self.rightBorrowTimeLabel removeFromSuperview];
//        [self.rightButton removeFromSuperview];
//    }
//    
//}
//
//


- (void)intervalSinceNow:(NSString *)theDate borrowStatus:(NSString *)status button:(UIButton *)button{
    
    NSString *title;
    
    NSDateFormatter *date = [[NSDateFormatter alloc]init];
    [date setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *newsDate = [date dateFromString:theDate];
    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
    [date setTimeZone:timeZone];
    NSDate *current_Date = [[NSDate alloc]init];
    // 间隔描述
    NSTimeInterval time = [newsDate timeIntervalSinceDate:current_Date];
   // int month = (int)time / (3600 *24 * 30);
    int days = (int)time / (3600 * 24);
    int hours = (int)time % (3600 * 24) / 3600;
    
    
    NSString *overDue = NSLocalizedString(@"overdue", nil);
    NSString *surplus = NSLocalizedString(@"surplus", nil);
    NSString *backBook = NSLocalizedString(@"backBook", nil);
    NSString *lost = NSLocalizedString(@"lostBook", nil);
    NSString *hour = NSLocalizedString(@"hour", nil);
    
    BOOL isChinese = [self systemOfTheCurrentLanguage];
    
    if ([status isEqualToString:@"0"]) {
        if (time < 0) {
            button.backgroundColor = [UIColor colorWithHexString:borrowOverTimeColor];
            if (days <= 0) {
                if (isChinese) {
                    title = [NSString stringWithFormat:@"%@%d%@",overDue, -hours, hour];
                }else{
                    title = [NSString stringWithFormat:@"%d%@%@",-hours,hour,overDue ];
                }
                [button setTitle:title forState:UIControlStateNormal];
            }else {
                if (isChinese) {
                    title = [NSString stringWithFormat:@"%@%d天", overDue,-days];
                }else{
                    title = [NSString stringWithFormat:@"%d天%@",-days, overDue];
                }
                
                [button setTitle:title forState:UIControlStateNormal];
            }
        }else{
            button.backgroundColor = [UIColor colorWithHexString:borrowNowColor];
            if (days <= 0) {
                if (isChinese) {
                    title= [NSString stringWithFormat:@"%@%d%@",surplus ,hours, hour];
                }else{
                    title= [NSString stringWithFormat:@"%d%@%@",hours,hour, surplus];
                }
                [button setTitle:title forState:UIControlStateNormal];
            }else{
                if (isChinese) {
                    title = [NSString stringWithFormat:@"%@%d天", surplus,days];
                }else{
                    title = [NSString stringWithFormat:@"%d天%@", days,surplus];
                }
                [button setTitle:title forState:UIControlStateNormal];
            }
        }
    } else if ([status isEqualToString:@"1"]){
        title = backBook;
        [button setTitle:title forState:UIControlStateNormal];
        button.backgroundColor = [UIColor colorWithHexString:backNowColor];
    }else{
        title = lost;
        [button setTitle:title forState:UIControlStateNormal];
        button.backgroundColor = [UIColor colorWithHexString:borrowOverTimeColor];
    }
    
}

#pragma mark - 判断系统当前语言
- (BOOL)systemOfTheCurrentLanguage{
    NSArray *languages = [NSLocale preferredLanguages];
    NSString *currentLanguage = [languages objectAtIndex:0];
    if ([currentLanguage isEqualToString:@"ja-CN"]) {
        return NO;
    }else{
        return YES;
    }
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
